package com.dataStructure.queue;


/**
 * 数组循环队列
 *该队列一定要空出一位
 */
public class CycleQueue {
    private int[] ar;
    private int rear;
    private int front;
    public CycleQueue(int number){
        this.ar = new int[number];

    }

    public void enQueue(int data) throws Exception{
        if ((rear+1) % ar.length == front){
            throw new Exception("该队列已满");
        }
        ar[rear] = data;
        rear = (rear+1)%ar.length;

    }

    public void deQueue() throws Exception{
        if (rear == front)
            throw new Exception("队列已空");
        int de = ar[front];

        front = (front+1)%ar.length;
    }
}
